package com.lt.utils.Activity;

import android.app.Activity;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author LiuTong
 */
public class ActivityManager {
    private static Set<Activity> activities = new HashSet<>();
    public static void addActivity(Activity activity){
        activities.add(activity);
    }

    public static void remove(Activity activity){
        Iterator<Activity> iterator = activities.iterator();
        if (iterator.hasNext()){
            if(iterator.next() == activity){
                iterator.remove();
            }
        }
    }
    public static void finishAllActivity(){
        for(Activity activity:activities){
            activity.finish();
        }
    }
    public static void finishActivity(Activity activity){
        if(activities.contains(activity)){
            activities.remove(activity);
            activity.finish();
        }
    }

    public static void Exit(){
        finishAllActivity();
    }
}
